package team.bluepen.order.web.servlet.user;

import team.bluepen.order.ErrorPack;
import team.bluepen.order.constant.ErrorCode;
import team.bluepen.order.util.Log;
import team.bluepen.order.web.servlet.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 退出登录
 * @author RollW
 */
@WebServlet(name = "UserLogoutServlet", urlPatterns = "/api/user/logout")
public class UserLogoutServlet extends BaseServlet {
    @Override
    protected void post(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        setJsonHeader(resp);
        req.getSession().invalidate();
        ErrorPack pack = new ErrorPack(ErrorCode.SUCCESS,
                ErrorCode.SUCCESS.toString());
        writeJson(resp, pack.toCodePack());
        Log.i("Logout success.");
    }
}
